﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cosmetic.DataEntity;
using System.Collections;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

namespace Cosmetic.Logic
{
    public class CityManager : LogicBase
    {

        static string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="theLevel"></param>
        /// <returns></returns>
        public static System.Data.DataTable SelectAllProvinces()
        {
            // string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(conStr);
            try
            {
                con.Open();
                string cmdStr = "select province,provinceid from dbo.provinces ";
                SqlCommand com = new SqlCommand(cmdStr, con);
                DataSet ds = new DataSet();
                SqlDataAdapter adap = new SqlDataAdapter(com);
                adap.Fill(ds);
                return ds.Tables[0];
            }
            finally
            {
                con.Close();
            }
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="theLevel"></param>
        /// <returns></returns>
        public static System.Data.DataTable SelectAllCityByProvinceid(string provinceid)
        {
            // string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(conStr);
            try
            {
                con.Open();
                string cmdStr = "select * from dbo.cities where provinceid = (select provinceid from dbo.provinces where provinceid = '" + provinceid + "') ";
                SqlCommand com = new SqlCommand(cmdStr, con);
                DataSet ds = new DataSet();
                SqlDataAdapter adap = new SqlDataAdapter(com);
                adap.Fill(ds);
                return ds.Tables[0];
            }
            finally
            {
                con.Close();
            }
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="theLevel"></param>
        /// <returns></returns>
        public static System.Data.DataTable SelectAllCity()
        {
            // string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(conStr);
            try
            {
                con.Open();
                string cmdStr = "select * from dbo.cities  ";
                SqlCommand com = new SqlCommand(cmdStr, con);
                DataSet ds = new DataSet();
                SqlDataAdapter adap = new SqlDataAdapter(com);
                adap.Fill(ds);
                return ds.Tables[0];
            }
            finally
            {
                con.Close();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="theLevel"></param>
        /// <returns></returns>
        public static System.Data.DataTable SelectAllAreaByCityid(string cityid)
        {
            // string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(conStr);
            try
            {
                con.Open();
                string cmdStr = "select * from dbo.areas where cityid = (select cityid from dbo.cities where cityid= '" + cityid + "')";
                SqlCommand com = new SqlCommand(cmdStr, con);
                DataSet ds = new DataSet();
                SqlDataAdapter adap = new SqlDataAdapter(com);
                adap.Fill(ds);
                return ds.Tables[0];
            }
            finally
            {
                con.Close();
            }
        }

        public static System.Data.DataTable SelectAllArea()
        {
            // string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(conStr);
            try
            {
                con.Open();
                string cmdStr = "select * from dbo.areas ";
                SqlCommand com = new SqlCommand(cmdStr, con);
                DataSet ds = new DataSet();
                SqlDataAdapter adap = new SqlDataAdapter(com);
                adap.Fill(ds);
                return ds.Tables[0];
            }
            finally
            {
                con.Close();
            }
        }


    }//end class
}
